<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>系统常态化运行评分系统</title>
    <link rel="stylesheet" href="../../component/pear/css/pear.css" />
    <style>
        .expand.pear-btn:hover {
            color: currentColor;
            background: none;
        }

        .expand.pear-btn {
            border: 1px solid rgba(255, 255, 255, 0)
        }
    </style>
</head>

<body class="pear-container">
    <div id="div-ext">
        <div class="layer-top">
            <form class="layui-form" action="" onsubmit="return false" lay-filter="lay-info">
            <div class="layui-card">
                <div class="layui-card-header" id="divHeader" style="float: right;">
                    <button id="btn" class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="lay-user-add">新增消息</button>
                </div>
            </div>
            <div class="layui-card" style="margin-top: 10px;">
                    <input type="hidden" name="id" />
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">类型</label>
                        <div class="layui-input-block">
                            <input type="radio" name="newsType" value="1" title="通知">
							<input type="radio" name="newsType" value="2" title="文件汇编" checked>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发布时间</label>
                        <div class="layui-input-block">
                            <input type="text" id="pulishTime" name="pulishTime" lay-verify="date" placeholder="请选择发布日期" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发布状态</label>
                        <div class="layui-input-block">
                            <input type="radio" name="state" value="1" title="草稿">
							<input type="radio" name="state" value="2" title="已发布" checked>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">内容</label>
                        <div class="layui-input-block">
                            <textarea id="remark" name="remark"  placeholder="请输入项目简介" class="layui-textarea"></textarea>
                        </div>
                    </div>
            </div>
        </form>
        </div>
    </div>
<script src="../../component/layui/layui.js"></script>
<script src="../../component/pear/pear.js"></script>
<script src="../../scripts/utils/request.js"></script>
<script src="../../scripts/utils/auth.js"></script>
<script src="../../scripts/utils/tinymceUtils.js"></script>
<script>
    var $,table,form,drawer,popup,notice,laydate
    layui.use(['table', 'form', 'jquery', 'drawer', 'popup','notice','laydate','tinymce','layer'], function() {
        table = layui.table;
        form = layui.form;
        $ = layui.jquery;
        drawer = layui.drawer;
        popup = layui.popup;
        notice = layui.notice;
        laydate= layui.laydate;
        var tinymce= layui.tinymce;
        var layer=layui.layer;

        var remark=initTinymce(tinymce,'remark');
        

        laydate.render({
            elem: '#pulishTime'
        });
        var index = parent.layer.getFrameIndex(window.name); 
        let selData= parent.getData();
        if(selData.id==''){
            $("#btn").text("新增消息");
        }else{
            $("#btn").text("修改消息");
        }
        form.val('lay-info',{
            "id":selData.id,
            "title":selData.title,
            "newsType":selData.newsType,
            "state":selData.state,
            "pulishTime":selData.pulishTime,
            "remark":selData.remark
        });
        /**
         * 新增/修改评分
         */
         form.on('submit(lay-user-add)',function (data){
            let reqData=data.field;
            reqData.remark=remark.getContent();
            if(!reqData.id||reqData.id==''){
                postAjax('/api/news/add',reqData,function (response){
                    parent.refresh();
                    parent.layer.close(index);
                },null);
            }else{
                postAjax('/api/news/modify',reqData,function (response){
                    parent.refresh();
                    parent.layer.close(index);
                },null);
            }
        });

    });
        
</script>
</body>

</html>